home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '90 / Other Stuff / Networking ƒ / ATP Sample App / packets / dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-18  |  2.1 KB  |  132 lines  |  [TEXT/KAHL]

  1. #include "packets.h"
  2.  
  3. word    theDelay = DEFAULT_DELAY,
  4.         theSize = DEFAULT_SIZE;
  5. char    theZone[33] = "*";
  6. char    theName[33] = "=";
  7. uword    theTestSize = TEST_SIZE_K;
  8. word     theBDSCount = DEFAULT_BDS_COUNT;
  9.  
  10. Configure()
  11. {
  12.     DialogPtr dp;
  13.     word item;
  14.     
  15.     dp = GetNewDialog(128, (Ptr)0, (WindowPtr)-1L);
  16.     
  17.     SetDialogNumber(dp, 5, theDelay);
  18.     SetDialogNumber(dp, 6, theSize);
  19.     SetDialogText(dp, 14, theName);
  20.     SetDialogText(dp, 8, theZone);
  21.     SetDialogNumber(dp, 10, theTestSize);
  22.     SetDialogNumber(dp, 12, theBDSCount);
  23.  
  24.     if (dp)
  25.         {
  26.         do    {
  27.             ModalDialog((ProcPtr)0, &item);
  28.             }
  29.         while (item > 2);
  30.         }
  31.     
  32.     if (item == 1)
  33.         {
  34.         GetDialogNumber(dp, 5, &theDelay);
  35.         GetDialogNumber(dp, 6, &theSize);
  36.         GetDialogText(dp, 14, theName, 32);
  37.         GetDialogText(dp, 8, theZone, 32);
  38.         GetDialogNumber(dp, 10, &theTestSize);
  39.         GetDialogNumber(dp, 12, &theBDSCount);
  40.         
  41.         if (theSize > 512)
  42.             { SysBeep(10); theSize = 512; }
  43.         }
  44.     
  45.     DisposDialog(dp);
  46. }
  47.  
  48. SetDialogNumber(dp, item, number)
  49. DialogPtr dp;
  50. uword item, number;
  51. {
  52.     word dtype;
  53.     Handle dhandle;
  54.     Rect dbox;
  55.     char text[256];
  56.     
  57.     GetDItem(dp, item, &dtype, &dhandle, &dbox);
  58.     if (dhandle)
  59.         {
  60.         sprintf(text, "%u", number);
  61.         CtoPstr(text);
  62.         SetIText(dhandle, text);
  63.         }        
  64. }
  65.  
  66. SetDialogText(dp, item, str)
  67. DialogPtr dp;
  68. word item;
  69. char *str;
  70. {
  71.     word dtype;
  72.     Handle dhandle;
  73.     Rect dbox;
  74.     char text[256];
  75.     
  76.     GetDItem(dp, item, &dtype, &dhandle, &dbox);
  77.     if (dhandle)
  78.         {
  79.         strcpy(text, str);
  80.         CtoPstr(text);
  81.         SetIText(dhandle, text);
  82.         }        
  83. }
  84.  
  85. GetDialogNumber(dp, item, number)
  86. DialogPtr dp;
  87. uword item, *number;
  88. {
  89.     word dtype;
  90.     Handle dhandle;
  91.     Rect dbox;
  92.     char text[256];
  93.     
  94.     GetDItem(dp, item, &dtype, &dhandle, &dbox);
  95.     if (dhandle)
  96.         {
  97.         GetIText(dhandle, text);
  98.         text[ text[0]+1 ] = '\0';
  99.         *number = atoi( text+1 );
  100.         return 1;
  101.         }
  102.     
  103.     return 0;
  104. }
  105.  
  106. GetDialogText(dp, item, str, max)
  107. DialogPtr dp;
  108. word item;
  109. char *str;
  110. word max;
  111. {
  112.     word dtype;
  113.     Handle dhandle;
  114.     Rect dbox;
  115.     char text[256];
  116.     
  117.     GetDItem(dp, item, &dtype, &dhandle, &dbox);
  118.     if (dhandle)
  119.         {
  120.         GetIText(dhandle, text);
  121.         text[ text[0]+1 ] = '\0';
  122.         if (text[0] > max)
  123.             text[max] = '\0';
  124.             
  125.         ptoccpy(str, text);
  126.         return 1;
  127.         }
  128.     
  129.     return 0;
  130. }
  131.  
  132.